package com.sy.employee.web;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sy.employee.ServiceEmployeeApplication;
import com.sy.employee.dao.po.EmployeePo;
import com.sy.employee.service.IEmployeeService;
import com.sy.employee.utils.ResultUtils;
import com.sy.employee.utils.ResultVo;
import com.sy.employee.web.fo.ArgsQueryEmployee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 部门信息表 前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2025-04-08
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Resource
    private IEmployeeService service;
    @Autowired
    private ServiceEmployeeApplication serviceEmployeeApplication;

    @GetMapping("/{id}/get")
    public ResultVo<EmployeePo> getEmployee(@PathVariable Integer id) {
        EmployeePo po = service.getById(id);
        return ResultUtils.success("查询成功", po);
    }

    @GetMapping("/get")
    public ResultVo<EmployeePo> getEmployee(ArgsQueryEmployee fo) {
        EmployeePo po = service.getById(fo.getId());
        return ResultUtils.success("查询成功", po);
    }

    @GetMapping("/list")
    public ResultVo<List<EmployeePo>> listEmployee(ArgsQueryEmployee fo) {
        List<EmployeePo> pos = service.listEmployee(fo);
        return ResultUtils.success("查询成功", pos);
    }

    @GetMapping("/page")
    public ResultVo<Page<EmployeePo>> pageEmployee(ArgsQueryEmployee fo) {
        Page<EmployeePo> poPage = service.pageEmployee(fo);
        return ResultUtils.success("查询成功", poPage);
    }

    @PostMapping("/put")
    public ResultVo<Void> addEmployee(@RequestBody EmployeePo po) {
        System.out.println(po);
        service.save(po);
        return ResultUtils.success();
    }

    @PostMapping("/post")
    public ResultVo<Void> updateEmployee(@RequestBody EmployeePo po) {
        service.updateById(po);
        return ResultUtils.success();
    }

    @PostMapping("/{id}/delete")
    public ResultVo<Void> deleteEmployee(@PathVariable Integer id) {
        service.removeById(id);
        return ResultUtils.success();
    }

    @PostMapping("/delete")
    public ResultVo<Void> deleteEmployee(@RequestBody EmployeePo po) {
        service.removeById(po.getId());
        return ResultUtils.success();
    }

}

